package com.design.movieticket.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.design.movieticket.common.base.constant.Result;
import com.design.movieticket.common.base.constant.ResultStatus;
import com.design.movieticket.common.dto.XPage;
import com.design.movieticket.entity.Income;
import com.design.movieticket.service.IncomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@Api(tags = "收入管理")
@RestController
@RequestMapping("/income")
public class IncomeController {
    @Resource
    private IncomeService incomeService;

    /** 分页查询 */
    @ApiOperation("收入信息分页展示")
    @GetMapping("/list/page")
    public Result findIncomeListByPage(Income income, XPage<Void> page) {
        IPage<Income> IncomeList = incomeService.page(XPage.toIPage(page), incomeService.buildQuery(income));
        return new Result(IncomeList, ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 新增或更新收入数据 */
    @ApiOperation("新增或更新收入数据")
    @PostMapping("/addOrUpdate")
    public Result addOrEditIncome(Income income) {
        incomeService.addOrUpdateIncomeInfo(income);
        return new Result(ResultStatus.SAVE_SUCCESS.getMsg(),ResultStatus.SAVE_SUCCESS.getCode());
    }

    /** 获取收入信息 */
    @ApiOperation("获取收入信息详情")
    @GetMapping("/getIncomeDetail/{id}")
    public Result getIncomeDetail(@PathVariable long id){
        return new Result(incomeService.getIncomeDetail(id),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 删除收入信息 */
    @ApiOperation("删除收入信息")
    @PostMapping("/delIncomeById/{id}")
    public Result delIncomeById(@PathVariable long id){
        incomeService.delIncomeById(id);
        return new Result(ResultStatus.DELETE_SUCCESS.getMsg(),ResultStatus.DELETE_SUCCESS.getCode());
    }
}
